<?php
namespace app\controller;

use think\exception\ValidateException;
use app\validate\Config as ConfigValidate;

class Config extends Base
{
    protected $middleware = ['checkAdmin'];

    protected function initialize()
    {
        parent::initialize();
        $this->logic = new \app\logic\Config();
    }

    /**
     * 配置
     */
    public function index()
    {
        if(request()->isAjax()) {
            $param = request()->param();
            try {
                validate(ConfigValidate::class)->check($param);
            } catch(ValidateException $e) {
                return $this->jsonReturn(config('status.verify'), $e->getError());
            }

            return $this->jsonReturn($this->logic->saveConfig($param));
        }
        return view("", [
            'config'    => $this->logic->getConfigAll()
        ]);
    }
}